<%@ page language="java" import="java.util.*,entity.*,dao.*,dao.impl.*" pageEncoding="utf-8" isELIgnored="false" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
BoardDao boardDao =new BoardDaoImpl();
TopicDao topicDao =new TopicDaoImpl();
UserDao  userDao =new UserDaoImpl();
Map mapBoard = boardDao.findBoard();
%>
<!DOCTYPE html>
<html>
    <head>
    	<base href="<%=basePath%>">
        <title>论坛首页</title>
        <style>
            *{margin:0;padding:0;}
            .divhead{
            margin-top:50px;
            height:50px; 
            text-align: center;
            line-height:50px; 
        }
            .divhead>p{
            text-shadow:#FF0000 0 0 10px;
            color:white;
            font-size:60px
        }
            .div2{
                margin-top:30px;
                text-align:center;
            }
            .div2>p{
                background-color: gray;
            }
            .div3{
                margin-top: 30px;
            }
            body{
            text-align:left;
            color: white;
        }
            table{
            border:2px solid burlywood;
            width:1000px;
            height:700px;
            margin:auto;
            /*合并为一个边框线*/
        }
            td{
            
            white-space: nowrap;

        }
            img{
            width:50px;
            height:50px;
        }
        </style>
        
    </head>
    <body background="img/background.jpg">
        <div class="divhead">
            <p>北京科技大学天津学院BBS</p>
        </div>
        <div class ="div2">
        <%if(session.getAttribute("user")==null){ %>
            <p>您尚未<a href="login.jsp" target ="_blank">登录</a> | <a href="reg.jsp" target ="_blank">注册</a> 
            <%}else{            
            	User loginUser =(User)session.getAttribute("user"); 
            %>
            	您好： ${sessionScope.user.UName}</p><a href="manage/doLogout.jsp">[登出]</a>
             <%} %>
        </div>
        <div class ="div3">
            <table border="1" >
                <tr>
                    <td colspan="2">论坛</td>
                    <td>主题</td>
                    <td>最后发表</td>
                </tr>
                <!-- 主版块 -->
                	<%
                	List listMainBoard =(List)mapBoard.get(new Integer(0));
                	for(int i =0;i<listMainBoard.size();i++){
                		Board mainBoard =((Board)listMainBoard.get(i));
                	 %>
                <tr>
                    <td colspan="4"><%=mainBoard.getBoardName() %></td>

                </tr>
                <!-- 子版块 -->
       				<%
                		List listSonBoard = (List)mapBoard.get(new Integer(mainBoard.getBoardId()));
                		for(int j=0;j<listSonBoard.size();j++){
                			Board sonBoard = (Board)listSonBoard.get(j);
                			String boardName=sonBoard.getBoardName();
                			Topic topic =new Topic();
                			User user =new User();
                			int boardId = sonBoard.getBoardId();
                			List listTopic = topicDao.findListTopic( 1, boardId);
                			
                			if( listTopic !=null && listTopic.size()>0){
                				topic =(Topic)listTopic.get(0);
                				user = userDao.findUser(topic.getUid());
                			}
                			
                	 %>
                <tr>
                    <td width="6%"></td>
                    <td><img src="img/C.jpg"><a href ="list.jsp?page=1&boardId=<%=boardId%>" ><%=boardName %></a></td>
                    <td><%= topicDao.findCountTopic(boardId) %></td>
                    <td>
                    	<a href="detail.jsp?page=1&boardId=<%=boardId%>&topicId=<%=topic.getTopicId()%>"><%=topic.getTitle() %></a>
                    	<br/>
							<span><%=user.getUName() %></span>
							<span>[<%=topic.getPublishTime() %>]</span>
                    	<br/>
                    	
                    </td>
                </tr>
           
                <%
                	}
                }
                 %>
            </table>
        </div>
    </body>
</html>